local skel = fk.CreateSkill {
  name = "emo__tianchen",
}

skel:addEffect("viewas", {
  anim_type = "offensive",
  pattern = "slash",
  prompt = "emo__tianchen-prompt",
  card_filter = function (self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type ~= Card.TypeBasic
  end,
  view_as = function (self, player, cards)
    if #cards ~= 1 then return end
    local name = Fk:getCardById(cards[1]).type == Card.TypeTrick and "fire__slash" or "thunder__slash"
    local card = Fk:cloneCard(name)
    card:addSubcard(cards[1])
    card.skillName = skel.name
    return card
  end,
  before_use = function (self, player, use)
    use.extra_data = use.extra_data or {}
    use.extra_data.emo__tianchen_user = player.id
    if use.card.name == "fire__slash" then
      use.additionalEffect = (use.additionalEffect or 0) + 1
    end
  end,
  enabled_at_response = function(self, player, response)
    return not response
  end,
})

skel:addEffect(fk.Damage, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if not player.dead and data.card and player:distanceTo(data.to) == 1 then
      local e = player.room.logic:getCurrentEvent():findParent(GameEvent.CardEffect)
      if e then
        local use = e.data
        return player.id == (use.extra_data or {}).emo__tianchen_user
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, 1)
    if not player.dead then
      player:drawCards(player:getLostHp(), skel.name)
    end
  end,
})

skel:addEffect("targetmod", {
  extra_target_func = function(self, player, skill, card)
    if card and card.name == "thunder__slash" and table.contains(card.skillNames, "emo__tianchen")  then
      return 1
    end
  end,
})

Fk:loadTranslationTable{
  ["emo__tianchen"] = "天嗔",
  [":emo__tianchen"] = "你可以：1.将一张锦囊牌当额外结算一次的火【杀】使用；2.将一张装备牌当目标上限+1的雷【杀】使用。以此法使用的【杀】对你距离为1的角色造成伤害后，你增加1点体力上限并摸等于已损失体力值的牌。",

  ["emo__tianchen-prompt"] = "将锦囊牌当额外结算一次的火【杀】使用；或将装备牌当目标上限+1的雷【杀】使用",
}


return skel
